<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<html>
<head>
    <title>支付</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="stylesheet" href="__STATIC_URL__/static/weui/style/weui.min.css?v2"/>
    <link href="__STATIC_URL__/static/css/ggk/activity-style.css?v=5" rel="stylesheet" type="text/css"/>
    <script src="__STATIC_URL__/static/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
    <script src="__STATIC_URL__/static/layer/layer.js"></script>

    <style>
        body {
            background: #f8f8f8;

        }

        .icon_sp_area span {
            font-size: 1.5em;
            color: #00c715;
        }

        .weui-msg {
            padding-top: 20px;
            text-align: center;

            background-color: #f5f5f5;
            padding-bottom: 20px;

        }

        .weui_icon_msg:before {
            font-size: 84px;
        }

        .weui-form-preview__hd .weui-form-preview__value {
            font-size: 1.6em;
            text-align: center
        }

        ul, li, ol, dl, dd, dt {
            list-style: none;
        }

        footer dt {
            margin-top: 10px;
        }

        footer {

            padding: 0 15px;
        }

        footer dl {
            position: relative;
        }

        footer img {
            width: 100%;
        }

        footer dd {
            position: absolute;
            left: 0;
            bottom: 2px;
            line-height: 30px;
            width: 100%;
            color: #fff;
            text-indent: 15px;
            background: rgba(0, 0, 0, 0.5);
        }

        #nav {
            font-size: 12px;
            padding-bottom: 15px;
        }

        #nav li {
            width: 100%;
            height: 0px;
            line-height: normal
        }

        #nav .item1 {
            width: 100%;
            border-bottom: 1px solid #dbdbdb;
            margin-bottom: -15px;
        }

        #nav li a {
            width: 100%;
            display: block;
            color: #dbdbdb;
            text-decoration: none;
            padding: 6px 5px;
            text-align: center;
        }

        #nav li span {
            background: #f8f8f8;
            padding: 6px 15px;
        }

        #nav li a span {
            font-size: 14px;
            color: #9d9d9d;
        }
        footer {
            margin-bottom: 15px;
        }
        .weui-btn{
            margin:20px;
        }
    </style>

</head>
<body>

<div class="page preview js_show">
    <div class="weui-msg">

        <!--<div class="weui-msg__text-area">-->
        <!--<h2 class="weui-msg__title">操作成功</h2>-->
        <!--<p class="weui-msg__desc">内容详情，可根据实际需要安排，如果换行则不超过规定长度，居中展现<a href="javascript:void(0);">文字链接</a></p>-->
        <!--</div>-->
    </div>

    <div class="page__bd">
        <div class="weui-form-preview">
            <div class="weui-form-preview__hd">
                <div class="weui-form-preview__item">

                    <span class="weui-form-preview__value">易订货</span>
                </div>
                <div class="weui-form-preview__item">

                    <span class="weui-form-preview__value"><font color='#76EE00'>￥{$info['price']}</font></span>
                </div>

            </div>
            <div class="weui-form-preview__bd">

                <div class="weui-form-preview__item">
                    <label class="weui-form-preview__label">订单详情:</label>
                    <span class="weui-form-preview__value">{$info['price_info']}</span>
                </div>
                <input type="hidden" name="mid" id="mid" value="{$user.mid}">
                <input type="hidden" name="openid" id="openid" value="{$user.openid}">
                <input type="hidden" name="orderid" id="orderid" value="">
                <input type="hidden" name="cardid" id="card_id" value="{$user.card_id}">
                <input type="hidden" name="price" id="price" value="{$info.price}">

            </div>
        </div>
        <br>
    </div>
</div>
<form action="" method="post">


    <a href="javascript:;" class="weui-btn weui-btn_primary" >支付</a>

</form>

</div>


</body>
<script>
    function getorder(mid) {
        var id = mid;
//            var cardid = $('#cardid').val();
        $.ajax({
            type: "POST",
            url: "{:url('carduser/getorder2')}",

            cache: false,
            async: false,
            data: {
                id: id,

            },


            success: function (data) {
                $('#orderid').val(data);

            }
        });
    }
    $(".weui-btn_primary").click(function () {


        var price = $('#price').val();
        var mid = $('#mid').val();
        getorder(mid);
        var openid = $('#openid').val();
        var orderid = $('#orderid').val();
        var card_id = $('#card_id').val();


        $.ajax({
            url: "{:url('ordergoods/pay')}",
            type: 'post',
            dataType: 'json',
            data: {

                price: price,
                mid: mid,
                openid: openid,
                orderid: orderid,
                card_id: card_id,

            },


            success: function (data) {
                   console.log(132,data)
                // return;
                if(data.code!=0){
                    layer.msg(data.message);
                    $("#iosDialog3").fadeIn(200);
                }
                if (typeof WeixinJSBridge == "undefined") {
                    if (document.addEventListener) {
                        document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                    } else if (document.attachEvent) {
                        document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                        document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                    }
                } else {
                    onBridgeReady(data);
                }
            }
        })
    })



    function onBridgeReady(sdata) {

        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', sdata,
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    paysuccess();
                }     // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
            }
        );

    };

    function paysuccess() {

        $.ajax({
            type: "POST",

            url: "{:url('ordergoods/r_payover')}",

            cache: false,
            dataType: "json",
            async: false,
            data: {
                id:{$user['mid']},
                orderid:$('#orderid').val(),
                cardid: $('#cardid').val(),
            },

            success: function (data) {
                // alert(data.url);

                if (data.code == 0) {
                    layer.msg(data.message);
                    setTimeout(function(){
                        window.location.href = data.url;

                },500)
                } else {
                    layer.msg(data.message);

                }
            }


        });
    }
</script>
</html>
